package thread.lock;

import java.util.concurrent.TimeUnit;

public class test {
    public static void main(String[] args) throws InterruptedException {
        SpinLock lock = new SpinLock();
        
        new Thread(()->{
            System.out.println(Thread.currentThread().getName() + "start");
            lock.myLock();
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                lock.myUnLock();
            }
        },"T1").start();

        TimeUnit.SECONDS.sleep(3);
        
        new Thread(()->{
            System.out.println(Thread.currentThread().getName() + "start");
            lock.myLock();
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                lock.myUnLock();
            }
        },"T2").start();
        

    }
}
